﻿using System;
using System.Collections.Generic;
using DDDNorthWind.AC.Products.Domain.Aggregate;
using DDDNorthWind.AC.Products.Domain.DomainEvents;
using DDDNorthWind.AC.Products.Domain.EventArgs;
using DDDNorthWind.AC.Products.Domain.ValueObject;
using DDDNorthWind.Core.Domain.Aggregate;
using DDDNorthWind.Core.Domain.Events;
using DDDNorthWind.Core.Domain.Identity;

namespace DDDNorthWind.AC.Products.Domain.Entities
{
    public class Product : AggregateRoot<ProductId, Guid>, IProductAggregateRoot
    {
        public Product(ProductId id)
            : base(id)
        {
            Size=ProductSizes.Empty;
            Prices = new List<ProductPrice>();
            Stock = new ProductStock();
        }
        public Product():base(new DefaultGuidIdentifierGenerator())
        {}

        protected override void CreateNewIdentity(IUniqueIdentifierGenerator<Guid> uniqueCreate)
        {
            Id = new ProductId(uniqueCreate.GetNewId());
        }

        public override ProductId Id { get; protected set; }
        protected override void RegisterAggregateEvents()
        {
            RegisterEvent<ProductSizedChanged>(OnProductSizeChanged);
        }

        private void OnProductSizeChanged(ProductSizedChanged obj)
        {
            throw new NotImplementedException();
        }


        public string SKU { get; set; }

        public string Name { get; set; }

        public bool IsActive { get; set; }

        public int QuantityPerUnit { get; set; }

        public ProductSizes Size { get; private set; }

        public List<ProductPrice> Prices { get;  private set; }

        public ProductStock Stock { get; private set; }


        public void AssignImportWeight(double weight)
        {
            throw new NotImplementedException();
        }

        public void AssignImportSizes(double high, double length, double width)
        {
            var weight = Size.Weight;
            var productSizes = new ProductSizes(high, width, length, weight);
            Size.UpdateValues(productSizes);

            Raise(new ProductSizedChanged(){Id = Id});



        }

       
    }
}
